import React, { useEffect } from 'react';
import { PageContainer } from '@ant-design/pro-layout';
import { Descriptions } from 'antd';
import { useModel } from '@@/plugin-model/useModel';
import { ethers } from 'ethers';
import { ExternalProvider } from '@ethersproject/providers/src.ts/web3-provider';

const getInfo = async () => {
  const provider = new ethers.providers.Web3Provider(
    window.ethereum as ExternalProvider,
  );
  const signer = provider.getSigner();
  // const signature = await signer.signMessage("Hello World");
  // console.log(signature)
  const address = await signer.getAddress();
  const balance = await provider.getBalance(address);
  const account: API.ModelsAccount = { address: address };
  return account;
};

const Welcome = () => {
  const { initialState, setInitialState } = useModel('@@initialState');
  const provider = initialState?.provider;

  if (!provider) {
    return;
  }

  useEffect(() => {
    provider.getGasPrice();
  }, []);

  const content = (
    <Descriptions size="small" column={2}>
      <Descriptions.Item label="钱包地址">
        {initialState?.currentAccount?.address}
      </Descriptions.Item>
      {/*<Descriptions.Item label="账户余额">{account?.balance}</Descriptions.Item>*/}
    </Descriptions>
  );

  return <PageContainer extraContent={content}></PageContainer>;
};

export default Welcome;
